<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<body>
<form id="informationForm" role="form" method="post" action="fireCheckControl/update">
    <input type="hidden" name="id" id="informationId" th:value="${entity.id}"/>
    <div class="form-group">
        <label for="deviceName">消防器材名称:</label>
        <input type="text" class="form-control" name="deviceName" id="deviceName" th:value="${entity.deviceName}">
    </div>
    <div class="form-group">
        <label for="areaName">所属区域:</label>
        <select type="text" class="form-control" name="areaName" id="areaName">

        </select>
    </div>
    <div class="form-group">
        <label for="equipState">当前器材状态:</label>
        <select type="text" class="form-control" name="equipState" id="equipState">

        </select>
    </div>
    <div class="form-group">
        <label for="equipCheck">具体详情:</label>
        <input class="form-control" name="equipCheck" id="equipCheck" placeholder="请输入巡检的具体详情"th:value="${entity.equipCheck}" />
    </div>
</form>
<script th:inline="javascript">
    <![CDATA[
    $(function () {
        $.post("dict/getType", {type: "AREAID_TYPE"},
            function (r) {
                var areaName = [[${entity.areaName}]];
                /*  alert("Data Loaded: " + JSON.stringify(r));*/
                for (var i = 0; i < r.data.length; i++) {
                    if (areaName == r.data[i].value) {
                        $("#areaName", window.top.document).append("<option selected=true  value=" + r.data[i].value + ">" + r.data[i].text + "</option>");
                    } else {
                        $("#areaName", window.top.document).append("<option  value=" + r.data[i].value + ">" + r.data[i].text + "</option>");
                    }

                }
            })
        $.post("dict/getType", {type: "FIRE_CHECK_STATE"},
            function (r) {
                var equipState = [[${entity.equipState}]];
                /*  alert("Data Loaded: " + JSON.stringify(r));*/
                for (var i = 0; i < r.data.length; i++) {
                    if (equipState == r.data[i].value) {
                        $("#equipState", window.top.document).append("<option selected=true  value=" + r.data[i].value + ">" + r.data[i].text + "</option>");
                    } else {
                        $("#equipState", window.top.document).append("<option  value=" + r.data[i].value + ">" + r.data[i].text + "</option>");
                    }

                }
            })
        // 楼栋之间的联动 啧啧啧
        $('#informationForm', window.top.document).bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                areaName: {
                    validators: {
                        notEmpty: {
                            message: '所属片区不能为空'
                        }
                    }
                },
                equipState: {
                    validators: {
                        notEmpty: {
                            message: '状态不能为空'
                        }
                    }
                },
                deviceName: {
                    validators: {
                        notEmpty: {
                            message: '器材名称不能为空'
                        }
                    }
                },
                equipCheck: {
                    validators: {
                        notEmpty: {
                            message: '具体详情不能为空'
                        }
                    }
                }
            }
        });

        // 绑定dialog的确定按钮的监听事件
        $("#btnOk", window.top.document).click(function () {
            $("#btnOk", window.top.document).attr("disabled", true);
            var bootstrapValidator = $("#informationForm", window.top.document).data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                $.post($("#informationForm", window.top.document).attr('action'), $("#informationForm", window.top.document).serialize(), function (e) {
                    if (e.result) {
                        refreshDoQuery();
                        window.Ewin.alert({message: '修改数据成功!'});
                    } else {
                        window.Ewin.alert({message: '修改数据失败!'});
                    }
                    $("#btnOk", window.top.document).attr("disabled", false);
                })
            } else {
                $("#btnOk", window.top.document).attr("disabled", false);
            }
        });

        // 重新刷新当前查询页的数据
        function refreshDoQuery() {
            var iframes = $(window.parent.document).contents().find(".J_iframe");
            for (var i = 0; i < iframes.length; i++) {
                if ($(iframes[i]).css("display") == 'inline') {
                    $('.modal-dialog', window.top.document).parent('div').remove()
                    $('body', window.top.document).find('.modal-backdrop').remove();
                    iframes[i].contentWindow.doQuery();
                    break;
                }
            }
        }
    })
    ]]>
</script>
</body>
</html>